The present disclosure generally relates to a computer system, and more particularly to sharing a swap device among one or more memory groups.
The available random access memory (RAM) in a computer is seldom enough to meet user needs or to satisfy memory-intensive applications. To solve this problem, operating systems may use a memory management technique called virtual memory, which maps virtual addresses used by a program into physical addresses in computer memory. Virtual memory combines the computer's RAM with temporary space on a swap device. When RAM runs low, virtual memory moves data from RAM to the swap device. Moving data between the RAM and swap device frees up RAM so that the computer can complete its work. With this technique, software within the operating system may provide a virtual address space that can exceed the capacity of real memory and thus reference more memory than is physically present in the computer.
A conventional operating system supports one or more swap devices that may be used to store or swap out virtual memory contents when memory for an application is overcommitted. A swap device is typically shared by all applications executing on the computer. If the operating system supports multiple swap devices and one swap device is full or is unavailable the operating system may fall back on another swap device and store data into the other swap device. The operating system may limit the amount of swap space that a group of applications may consume or may disable the use of swap devices for the group of applications as a whole; this may have limitations. For example, the swap device may be a physical device that has a limited number of interrupts or a limited number of channels for communication with the operating system. Accordingly, it may be difficult to ensure service because a single physical device that is shared among applications can slow down other applications when more than one application is attempting to access the swap device. Swap space may refer to what is used when the amount of RAM is full. If the system needs more memory resources and the RAM is full, inactive pages in memory are moved to the swap space. Swap space may be located on a hard drive, which has a slower access time than physical memory.
Additionally, a conventional operating system may use various memory management techniques to optimize memory resource usage between RAM and a swap device. For example, in the paging memory-management scheme, the operating system retrieves data from the swap device in same-size blocks called memory pages. A page may refer to a memory page. In an example, pages can be moved to RAM or they can be evicted to external storage. Swapping or (paging) is generally known as a performance killer because it can cause high I/O activity on swap devices or files on disk. To counteract this disadvantage, paging may be disabled. When paging is disabled, however, the memory pressure gets higher and the operating system has lower file system cache available because it competes with the process code and data more frequently. One solution to solve this problem may be to put a lot of RAM into the computer to ensure that the amount of RAM is greater than what the applications executing on the computer will ever need; putting this amount of RAM into the machine, however, may be quite expensive.
In the memory-mapped memory-management scheme, an application may invoke a system call that creates a memory mapping. In an example, the system call creates a file mapping that maps a region of a file directly into a calling process's virtual memory. Once a file is mapped, its contents can be accessed by operations on the bytes in the corresponding memory region. An application may obtain a range of memory that is backed by a specific file, which is per application, and may have a high level of control over placement of its data. The application requests access to the specific file and stores this information in the memory that is backed by the specific file. With the memory-mapped memory-management scheme, the application informs the operating system that a particular page is backed by a particular swap device. The particular page may be considered not anonymous and automatically loaded from the file as required.